import React from 'react';
import styles from '@/pages/Organization/EmployeeManage/components/EmployeeCard/index.less';
import IconFont from '@/components/IconFont';
import { message, Modal, Popover } from 'antd';
import { useRequest } from '@/hooks';
import { getInformation } from '@/services/user';
import { eventTrack } from '@/utils/track';

/**
 * 员工信息头部 - 邀请完善个人信息
 */
const ControlsItemInviteImproveInfo = ({ employeeInfo, ...rest }) => {
    const { run: fetchInviteImprove } = useRequest(getInformation, {
        manual: true
    });

    const handleShowModal = () => {
        eventTrack({
            eventName: 'organization_staff_detail_invite_click',
            eventProps: { label: '邀请完善个人信息' }
        });
        Modal.confirm({
            title: '是否邀请员工完善个人档案?',
            content: '员工会收到工作通知的消息推送',
            centered: true,
            maskClosable: true,
            okText: '确定',
            cancelText: '取消',
            onOk: () =>
                new Promise((resolve, reject) => {
                    fetchInviteImprove({
                        employeeCode: employeeInfo.employeeCode
                    }).then(({ code, msg }) => {
                        if (code === 10000) {
                            // eventTrack({
                            //     eventName: 'organization_staff_detail_invite_submit_click',
                            //     eventProps: { label: '邀请完善个人信息-确定', status: 0 }
                            // });
                            resolve();
                        } else {
                            // eventTrack({
                            //     eventName: 'organization_staff_detail_invite_submit_click',
                            //     eventProps: { label: '邀请完善个人信息-确定', status: 1, error_info: res.msg }
                            // });
                            message.error(msg);
                            reject();
                        }
                    });
                }),
            onCancel: async () => {
                // 埋点
                // await eventTrack({
                //     eventName: 'organization_staff_detail_invite_cancel_click',
                //     eventProps: { label: '邀请完善个人信息-取消' }
                // });
            }
        });
    };

    // render
    return (
        <Popover content="邀请完善个人信息">
            <div className={styles.employeeControlsItem} onClick={handleShowModal} {...rest}>
                <IconFont icon="iconlistfunction_readyinterview_icon_default" />
            </div>
        </Popover>
    );
};

export default ControlsItemInviteImproveInfo;
